package com.biyu.monitormanage.common.utils;

import com.biyu.monitormanage.model.bo.PoliceBo;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * 报警工具类
 * @author 15491
 */
@Data
public class PoliceUtils {
    private final static String MAIL_COMMENT = "[哈喽机房监测] 当前告警机器及参数为：";
    private final static String MAIL_COMMENT1 = "告警结果为：";
    private final static String MAIL_COMMENT2 = "请及时处理！        本短信为毕设项目功能之一，如非黑龙江大学毕某相识之人接收此到邮件，请忽略本邮件！给您带来的不便请谅解！";

    private StringBuilder param;
    private StringBuilder val;

    private PoliceUtils(StringBuilder param, StringBuilder val) {
        this.param = param;
        this.val = val;
    }

    public static PoliceUtils getComment(List<PoliceBo> mailPoliceBoList) {
        StringBuilder param = new StringBuilder(" ");
        StringBuilder val = new StringBuilder(" ");
        mailPoliceBoList.forEach(policeBo -> {
            param.append(policeBo.getParamKey()).append("/ ");
            val.append(policeBo.getRealVal()).append("/ ");
        });
        return new PoliceUtils(param, val);
    }

    public String fromMail(String machineName) {
        return MAIL_COMMENT + machineName + this.getParam().toString() + MAIL_COMMENT1 + this.getVal().toString() + MAIL_COMMENT2;
    }

    public String[] fromMessage(String machineName) {
        List<String> strings = new ArrayList<>();
        strings.add(machineName + this.getParam().toString());
        strings.add(this.getVal().toString());
        return strings.toArray(new String[2]);
    }

    public static String getMailComment(List<PoliceBo> mailPoliceBoList, String machineName) {
        StringBuilder param = new StringBuilder(" ");
        StringBuilder val = new StringBuilder(" ");
        mailPoliceBoList.forEach(policeBo -> {
            param.append(policeBo.getParamKey()).append("/ ");
            val.append(policeBo.getRealVal()).append("/ ");
        });
        return MAIL_COMMENT + machineName + param + MAIL_COMMENT1 + val + MAIL_COMMENT2;
    }
}
